#ifndef QENVIRONMENT_H
#define QENVIRONMENT_H

#include <QWidget>
#include <physics>

#include <chrono>

using namespace std::chrono;
using physics::Environment;
using physics::RigidBody;
using physics::scalar;

class QEnvironment : public QWidget
{
    Q_OBJECT
    Environment env;
    bool _running;
    time_point<monotonic_clock> _last_update;
    RigidBody *active;
    scalar aMass;
protected:
    void timerEvent(QTimerEvent *);
    virtual void mousePressEvent(QMouseEvent *);
    virtual void mouseMoveEvent(QMouseEvent *);
    virtual void mouseReleaseEvent(QMouseEvent *);

public:
    explicit QEnvironment(QWidget *parent = 0);

    virtual void resizeEvent(QResizeEvent *);
    virtual int startTimer(int milli);
    virtual void killTimer(int id);
    virtual void paintEvent(QPaintEvent *);

    scalar getActiveMass() const;
    scalar getActiveElasticity() const;
    scalar getActiveSize() const;
signals:
    void activeChanged(bool);
public slots:
    void setActiveSize(int);
    void setActiveElasticity(int);
    void setActiveMass(double);
    void setGravity(double);
    void addBody(RigidBody*);
};

#endif // QENVIRONMENT_H
